/*
 * Copyright 2008 the Breachwalls OSS project and the Others.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
${template.generateJavaPackageSentence()}

<#list template.generateJavaImportClassSentences() as item>
${item}
<#if !item_has_next>

</#if>
</#list>
/**
 * ${model.getDescription()}.
 * @author todoken
 * @version $Revision$
 */
<#if !model.isAbstractClass()>
@${template.addImportFullClassName("javax.persistence.Entity")}
@${template.addImportFullClassName("javax.persistence.Table")}(name = "${template.getTableName()}")
</#if>
${template.getClassDefineSentence()}${model.getShortClassName()}${template.generateExtendsClassSentence()} implements ${template.addImportFullClassName("java.io.Serializable")} {

    /**
     * シリアルバージョンID.
     */
    private static final long serialVersionUID = 1L;

<#list model.getModelProperties() as property>
    /**
     * ${property.getDescription()}.
     */
<#if template.isIdentify(property)>
    @${template.addImportFullClassName("javax.persistence.Id")}
</#if>
    @${template.addImportFullClassName("javax.persistence.Column")}(name = "${template.getColumnName(property)}"<#if template.isNotNull(property) || template.isIdentify(property)>, nullable = false</#if>)
    @${template.addImportFullClassName("org.hibernate.annotations.Type")}(type = "com.breachwalls.brahma.persistence.GenericHibernateUserType", parameters = {
        @${template.addImportFullClassName("org.hibernate.annotations.Parameter")}(name = "datatype", value = "${property.getModel().getClassName()}")
    })
    private ${template.addImportFullClassName(property.getModel())} ${property.getName()};

</#list>
<#if model.isAbstractClass()>
    /**
     * ${model.getDescription()}を構築する.
     */
    protected ${model.getShortClassName()}() {
    }

<#else>
    /**
     * ${model.getDescription()}を構築する.
     */
    public ${model.getShortClassName()}() {
    }

</#if>
<#list model.getModelProperties() as property>
    /**
     * ${property.getDescription()}を取得する.
     * @return ${property.getDescription()}
     */
    public ${template.addImportFullClassName(property.getModel())} get${template.getMethodName(property)}() {
        return ${property.getName()};
    }

    /**
     * ${property.getDescription()}を設定する.
     * @param new${template.getMethodName(property)} ${property.getDescription()}
     */
    public void set${template.getMethodName(property)}(${template.addImportFullClassName(property.getModel())} new${template.getMethodName(property)}) {
        this.${property.getName()} = new${template.getMethodName(property)};
    }

</#list>
<#if !model.isAbstractClass()>
    /**
     * 文字列で取得する.
     * @return 文字列に変換した内容
     */
    @Override
    public String toString() {
        ${template.addImportFullClassName("org.apache.commons.lang.builder.ToStringBuilder")} builder = new ${template.addImportFullClassName("org.apache.commons.lang.builder.ToStringBuilder")}(this, ${template.addImportFullClassName("org.apache.commons.lang.builder.ToStringStyle")}.MULTI_LINE_STYLE);
<#list model.getModelProperties() as property>
<#if template.isNotNull(property) || template.isIdentify(property)>
        builder.append(${property.getName()}.toString());
</#if>
</#list>
        return builder.toString();
    }

    /**
     * ${model.getDescription()}のハッシュコードを取得する.
     * @return ${model.getDescription()}のハッシュコード
     */
    @Override
    public int hashCode() {
        final int hash1 = 17;
        final int hash2 = 37;
        ${template.addImportFullClassName("org.apache.commons.lang.builder.HashCodeBuilder")} builder = new ${template.addImportFullClassName("org.apache.commons.lang.builder.HashCodeBuilder")}(hash1, hash2);
<#list model.getModelProperties() as property>
<#if template.isNotNull(property) || template.isIdentify(property)>
        builder.append(${property.getName()}.hashCode());
</#if>
</#list>
        return builder.toHashCode();
    }

    /**
     * 引数のオブジェクトと同値であるかチェックする.
     * @param target このオブジェクトと同値であるか比較するオブジェクト
     * @return 比較した結果、同値であると見なされた場合、TRUEを返す
     */
    @Override
    public boolean equals(final Object target) {
        if (target == this) {
            return true;
        }
        if (target == null || !(target instanceof ${model.getShortClassName()})) {
            return false;
        }
        ${template.addImportFullClassName("org.apache.commons.lang.builder.EqualsBuilder")} builder = new ${template.addImportFullClassName("org.apache.commons.lang.builder.EqualsBuilder")}();
        ${model.getShortClassName()} o = (${model.getShortClassName()}) target;
<#list model.getModelProperties() as property>
<#if template.isNotNull(property) || template.isIdentify(property)>
        builder.append(get${template.getMethodName(property)}(), o.get${template.getMethodName(property)}());
</#if>
</#list>
        return builder.isEquals();
    }

</#if>
}
